home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_300
/
344_01
/
cflow.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-12-03
|
15KB
|
516 lines
/*
HEADER: CUG236;
TITLE: Function Abstractor;
DATE: 04/19/1987;
DESCRIPTION: "Abstracts C function calls and declarations from a C
source and produces a listing of the program's calling
hierarchy."
VERSION: 3.0;
KEYWORDS: Flow Analysis, Flow Analyzer;
FILENAME: CFLOW.C;
SEE-ALSO: CFLOW.DOC;
COMPILERS: vanilla;
AUTHORS: W. C. Colley III, Mark Ellington;
*/
/*
** CFLOW.C : find module call structure of c program
** refer to cflow.doc for how to use
** Mark Ellington
** 05-27-84
**
** Ported to portable C. Required the following changes:
**
** 1) Stripped BDS C hooks.
** 2) Stripped C/80 hooks.
** 3) Allowed for presence/absence of header files "ctype.h"
** and "string.h".
** 4) Allowed for possible pre-definition of constants TRUE,
** FALSE, and EOF.
** 5) Made variable fptr type FILE * instead of int.
** 6) Added a #define for the max line length.
** 7) Made preprocessor directive rejection logic smarter.
** 8) Removed name conflict between our fgets() and the std
** library fgets() by changing ours to get_source_line().
** William C. Colley, III
** 04-19-87
*/
#include <stdio.h>
/*
* Portability Note: The AZTEC C compilers handle the binary/text file
* dichotomy differently from most other compilers. Uncomment the following
* pair of #defines if you are running AZTEC C:
*/
/*
#define getc(f) agetc(f)
#define putc(c,f) aputc(c,f)
*/
/* Portability Note: If you do not have a header file "ctype.h",
uncomment the following #define so that the program will look for
library support. */
/* #define NO_CTYPE_H */
#ifdef NO_CTYPE_H
extern int isalnum();
#else
#include <ctype.h>
#endif
/* Portability Note: If you do not have a header file "string.h",
uncomment the following #define so that the program will look for
library support. */
/* #define NO_STRING_H */
#ifdef NO_STRING_H
extern int strcmp();
#else
#include <string.h>
#include <dos.h>
#include <dir.h>
#endif
/* Portability Note: A few compilers don't know the additional type
void. If yours is one of these, uncomment the following #define. */
/* #define void int */
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
#ifndef EOF
#define EOF -1
#endif
#define LINE_LENGTH 256 /* Max line length program can handle. */
#define PAGE_LENGTH 55 /* lines per page */
FILE *fptr; /* input file pointer */
int level; /* keep track of level of open "{"s */
char name[LINE_LENGTH]; /* module name buffer */
char ins[LINE_LENGTH]; /* source input line buffer */
int curchar; /* current character in input line
buffer array subscript */
unsigned short int linenum; /* current line number */
unsigned short int linecnt; /* hidden line number */
int function = FALSE; /* flag for level zero only */
char filename[128]; /* holder for filename */
short int lpp; /* holder for lines per page */
struct date today; /* structure for todays date */
struct time now; /* structure for current time */
short int pageno; /* holder for page number */
struct ffblk ffblk; /* holder for file structure */
/* Fixed bug that makes _ characters lop off the beginning of function
names. WCC3. */
/**********************************************************************/
int main(argc,argv)
int argc;
char *argv[];
{
void modules(), prt_hdr();
int i, done, filenum;
unsigned long int ttllines;
if (argc < 2) {
fprintf(stderr,"\nUsage: cflow infilename.ext [-f] ");
return TRUE;
}
if (done = findfirst(argv[1], &ffblk, 0)) {
fprintf(stderr,"\nCan't open %s\n",argv[1]);
return TRUE;
}
if (argc > 2)
if (argv[2][0] == '-' && (argv[2][1] == 'f' || argv[2][1] == 'F'))
function = TRUE;
else {
fprintf(stderr,"Second parameter is either '-f' or '-F'.");
return TRUE;
}
getdate(&today);
gettime(&now);
filenum = 0;
ttllines = 0;
while (!done) {
for (i = 0; ffblk.ff_name[i]; i++)
filename[i] = toupper(ffblk.ff_name[i]);
filename[i] = NULL;
if (!(fptr = fopen(filename,"r")))
break;
if (!function) {
pageno = 0;
prt_hdr();
}
else
fprintf(stderr,"File: %s\n", filename);
if (filenum++ > 1)
ttllines += linenum;
linenum = linecnt = 0;
modules();
fclose(fptr);
done = findnext(&ffblk);
}
if (filenum > 1)
fprintf(stderr, "Processed %d files, %u lines\n", filenum, ttllines);
return FALSE;
}
/**********************************************************************/
void modules() /* find function declarations and calls */
{
char c;
int i, dquote, defcont;
int incom; /* comment flag */
int decl; /* module declaration line flag */
int quoted; /* within " quotes " */
int header; /* within function header (before 1st '{') */
int lookbak();
void comout(), modname(), prt_hdr();
incom = quoted = header = defcont = dquote = FALSE;
level = 0;
while (fgets(ins, LINE_LENGTH, fptr)) { /* read a line of source */
linenum++;
decl = FALSE; /* assume nothing */
curchar = 0;
while (ins[curchar]) { /* read for significant characters */
comment:
if (ins[curchar] == '/' && (!quoted)) /* comments ? */
if (incom) {
if (curchar && (ins[curchar-1] == '*')) {
incom = FALSE;
curchar++;
}
}
else
if (ins[curchar+1] == '*') {
incom = TRUE;
curchar += 2;
if (ins[curchar] == '/')
curchar++;
}
if (!incom) {
if (defcont) { /* delete preprocessor continued lines */
def_cont:
defcont = TRUE;
for (i = curchar; ins[i]; i++)
switch (ins[i]) {
case '\\':
i++;
break;
case '\'':
if (!dquote) {
if (ins[++i] == '\\')
i++;
i++;
}
break;
case '"':
dquote = !dquote;
break;
case '/':
if (!dquote)
if (ins[i+1] == '*') {
curchar = i;
goto comment;
}
break;
} /* end switch */
if (ins[i-2] != '\\' || ins[i-1] != '\n